package test01.way;

import entity.Student;

import java.lang.reflect.Constructor;

/**
 *  获取类的 Class 对象 -- 方法一 - Class.forName("包名.类名")
 * @Author lzp
 * @Date 2024-03-25
 */
public class Test01 {
    public static void main(String[] args) throws Exception {
        Class<?> clazz =Class.forName("entity.Student");

        Constructor<?> constructor = clazz.getConstructor();
        Object obj = constructor.newInstance();
        if (obj instanceof Student) {
            Student stu = (Student) obj;
            stu.sayHello("廖神");
        }
    }
}
